<?php
/**
 *
 * 版权所有：恰维网络<qwadmin.qiawei.com>
 * 作    者：寒川<hanchuan@qiawei.com>
 * 日    期：2016-09-20
 * 版    本：1.0.0
 * 功能说明：后台首页控制器。
 *
 **/

namespace Qwadmin\Controller;

class UserController extends ComController
{
    public function index()
    {
    	$db = M("member");
		// $apost = $glist[0]['post'];
				
		$count = $db->count();

		$pagecount = 10;
		$page = new \Think\Page($count , $pagecount);

		$page->parameter = $row; //此处的row是数组，为了传递查询条件
		$page->setConfig('first');
		$page->setConfig('prev','上一页');
		$page->setConfig('next','下一页');
		$page->setConfig('last','尾页');
		$page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% 第 '.I('p',1).' 页/共 %TOTAL_PAGE% 页 ( '.$pagecount.' 条/页 共 %TOTAL_ROW% 条)');
		$show = $page->show();
		$list = $db->order('post desc')->limit($page->firstRow.','.$page->listRows)->select();
				
		$this->assign('list',$list);
		$this->assign('page',$show);
				
		$this->display();
    }




    public function sou()
    {
    	
          $list = $_POST;
          $wname = $list['name'];
          // dump($list);
          // exit;
    
          // $data['name']= array('like','%'.$wname.'%');
          $cname['user']= array('like','%'.$wname.'%');
          // $data['x_type'] = $list['x_type'];
          if (empty($wname)) {
            echo '1111';
            exit;
          }
          $wlist = M('member')->where($cname)->select();
          // dump($wlist);
          // exit;
          if (!empty($wlist)) {
             // $arr = M('stock')->where($data)->select();
              $this->ajaxReturn($wlist);
          }else{
            echo '2222';
          }
    }





    public function edit()
    {
       $uid = isset($_GET['uid']) ? intval($_GET['uid']) : false;
        if ($uid) {
            //$member = M('member')->where("uid='$uid'")->find();
            $prefix = C('DB_PREFIX');
            $user = M('member');
            $member = $user->field("{$prefix}member.*,{$prefix}auth_group_access.group_id")->join("{$prefix}auth_group_access ON {$prefix}member.uid = {$prefix}auth_group_access.uid")->where("{$prefix}member.uid=$uid")->find();

        } else {
            $this->error('参数错误！');
        }

        $usergroup = M('auth_group')->field('id,title')->select();
        // dump($member);
        // exit;
         $ulist = M('member')->select();

        $this->assign('ulist', $ulist);
        $this->assign('usergroup', $usergroup);

        $this->assign('member', $member);
        $this->display();
    }




    function del()
    {
      // dump(I());
      // exit;
      $uid = $_POST['id'];
      if (M('member')->where(['uid'=>$uid])->delete() > 0) {
          echo '1111';
      }else{
          echo '2222';
      }
      
    }


}